﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Cms.Core.AspNetMvc.Mvc;
using Cms.Core.Data.Model;
using Cms.Core.Infrastructure.Common;
using Microsoft.AspNetCore.Mvc;
using Cms.Core.Infrastructure.Extension;
using Cms.Core.Infrastructure.Dependency;
using Microsoft.Extensions.Logging;
using Cms.Core.Infrastructure.Log;
using Cms.Core.Application.Service.Dto;
using Cms.Core.Infrastructure;
using Cms.Core.Infrastructure.Ui;
using Microsoft.AspNetCore.Authorization;
using Cms.Core.Infrastructure.Attributes;
using Cms.Core.Infrastructure.ExpressionUtil;
using Cms.Core.Data.UnitOfWork;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Authentication;
using Cms.Core.AspNetMvc.Mvc.Filter;
using Cms.Core.Infrastructure.Filter;

namespace Cms.Core.Web.Controllers
{
    /// <summary>
    /// 测试
    /// </summary>

    [Route("api/[controller]")]
    [ApiController]
    [Authorize]
    //[Authorize(Policy = "Permission")]
    public class ValuesController : ControllerBase
    {
        private readonly IUnitOfWork _unitOfWork;

        public ValuesController(IUnitOfWork unitOfWork)
        {
            _unitOfWork = unitOfWork;
        }

        [CommonPermission]
        // GET api/values
        [HttpGet]
        public async Task<ActionResult> Get()
        {

        
       var dd= User.Identity;

            //动态生成表达式目录树
            var parser = new CmsExpressionParser<SysUser>();
            List<CmsConditions> conditions = new List<CmsConditions>();
            conditions.Add(new CmsConditions() {

                Operator= CmsOperatorEnum.Equal,
                Key= "UserName",
                Value= "大黄瓜",
                ValueType= "string"
            });

            conditions.Add(new CmsConditions()
            {

                Operator = CmsOperatorEnum.Equal,
                Key = "AccountNumber",
                Value = "",
                ValueType = "string"
            });
            var filter = parser.ToExpression(conditions);


            //var sql = _unitOfWork.SqlQuery("SELECT * FROM[Cms.Core].[dbo].[SysUser] where Id=@Id", new Dictionary<string, object>() { { "Id", "D6D0A332-C4A6-4866-718F-08D6A54B4892" } });

            //var ddd = await _unitOfWork.SqlQueryAsync<SysUser>("SELECT * FROM[Cms.Core].[dbo].[SysUser]", new Dictionary<string, object>() { { "Id", "D6D0A332-C4A6-4866-718F-08D6A54B4892" } });
            OrderCondition<SysUser> orderCondition = new OrderCondition<SysUser>(o => o.UserName);
            return new JsonResult(new { Success =true});
        }

        // GET api/values/5
        [HttpGet("{id}")]
        public ActionResult<string> Get(int id)
        {
            return "value";
        }

        // POST api/values
        [HttpPost]
        public void Post([FromBody] string value)
        {
        }

        // PUT api/values/5
        [HttpPut("{id}")]
        public void Put(int id, [FromBody] string value)
        {
        }

        // DELETE api/values/5
        [HttpDelete("{id}")]
        public void Delete(int id)
        {
        }
    }
}
